package com.xxx.controller;

import com.xxx.common.Result;
import com.xxx.feignclient.OrderClient;
import com.xxx.pojo.ShoppingCart;
import com.xxx.util.ThreadLocalUntil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.filter.OrderedFilter;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private OrderClient orderClient;

    @PostMapping("/save")
    public Result saveShop(@RequestBody List<ShoppingCart> cartList) {

        Long currentId = ThreadLocalUntil.getCurrentId();

        cartList.stream().forEach(shoppingCart -> {
            shoppingCart.setUserId(currentId);
        });
        log.info("shoppingCart:{}",cartList);

        Result result = orderClient.saveShop(cartList);

        return result;
    }

    @GetMapping("/shopCart")
    public Result getShop(){
        Long currentId = ThreadLocalUntil.getCurrentId();
        Result result = orderClient.getShop(currentId);
        log.info("result:{}",result);
        return result;
    }
}
